from manimlib import *
from numpy import square
import numpy as np

class SquareToCircle(Scene):
    #75cfb8
    #浅绿
    #bbdfc8
    #浅黄
    #f0e5d8
    #深黄
    #ffc478
    def construct(self):
        self.camera.background_color = WHITE
        axes = Axes(
            x_range=[0, 40, 10],
            y_range=[0, 40, 10],
            x_length=6,
            y_length=6,
            axis_config={
                "color": BLACK,
                "numbers_to_include": np.arange(0, 40.01, 10),
                },
            tips=False,
        )
        self.add(axes.get_axis_labels())
        axes.x_axis.numbers.set_color(BLACK)
        axes.y_axis.numbers.set_color(BLACK)

        f1=axes.get_graph(lambda x:x+7,color='#75cfb8',x_range=[0,30]).set_stroke(width=10)
        f2=axes.get_graph(lambda x:x,color='#bbdfc8',x_range=[0,35]).set_stroke(width=10)
        f3=axes.get_graph(lambda x:x-5,color='#ffc478',x_range=[5,35]).set_stroke(width=10)
        self.add(axes.get_graph_label(f1,'y=x+7',direction=DOWN),axes.get_graph_label(f2,'y=x',direction=DOWN,),axes.get_graph_label(f3,'y=x-5',direction=DOWN))
        dot1=Dot(color=RED).move_to(axes.c2p(0,30))
        dot2=Dot(color=RED).move_to(axes.c2p(30,30))
        dot3=Dot(color=RED).move_to(axes.c2p(30,0))
        axes.add_coordinates([5,0],[0,7]).set_color(BLACK)
        self.add(Line(dot1.get_corner(ORIGIN),dot2.get_corner(ORIGIN)).set_color(BLACK).set_stroke(width=10),Line(dot3.get_corner(ORIGIN),dot2.get_corner(ORIGIN)).set_color(BLACK).set_stroke(width=10))
        def p(x,y):
            return Dot().move_to(axes.c2p(x,y)).get_corner(ORIGIN)
        self.add(Polygon(p(0,0),p(5,0),p(30,25),p(30,30),p(23,30),p(0,7),color=GRAY).set_fill(color=GRAY,opacity=0.5).set_stroke(opacity=0))
        self.add(Tex('y>x').shift(LEFT*2),Tex('y<x').shift(DOWN*2))
        self.add(axes,f1,f2,f3,)
        self.wait(1)